// util.cpp
// Copyright (C) 2008 Sam Bateman
// samuel.bateman@gmail.com
//
// This file is part of DVD On Fire.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

//! @file util.cpp
//! @author Sam Bateman
//! @brief Source file for the utility functions.

#include <cstdio>
#include <string>
#include "util.h"
using namespace std;

// (C macros) + (C++ templates) = awesome!
#define NUM_TO_STR(type, typestr) \
    template <> string numToStr(type n) \
    { \
        char str[30]; \
        sprintf(str, "%" #typestr, n); \
        return str; \
    }

namespace dvdonfire
{
    namespace lib
    {
        //! @fn string numToStr(T n)
        //! @brief Converts a number to string.
        //! @param n Number to convert.
        //! @return String representation of n.
        //!
        //! This function is only implemented for types @c int, @c float, @c
        //! off_t, and @c size_t though it would be trivial to add others.
        NUM_TO_STR(int,    d  )
        NUM_TO_STR(float,  g  )
        NUM_TO_STR(off_t,  llu)
        NUM_TO_STR(size_t, u  )
    }
}
